package bookstore.controller;

import bookstore.handle.Msg;
import bookstore.mapper.OrderMapper;
import bookstore.mapper.UserMapper;
import bookstore.model.Order;
import bookstore.service.OrderService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class orderController {
    @Autowired
    OrderMapper orderMapper;

    @Autowired
    OrderService orderService;

    @Autowired
    UserMapper userMapper;

    //得到用户所有的订单
    @RequestMapping("/getAllOrder")
    public Object getAllOrder(Integer userId) {
        return orderService.allOrder(userId);
    }

    //删除订单
    @RequestMapping("/delOrder")
    public Object delOrder(List<Integer> listOrderNum) {
        return orderService.delOrder(listOrderNum);
    }

    //创建订单
    @RequestMapping("/addOrder")
    public Object addOrder(Integer userId, String strToJson) {
        if(null==userId){
            return new Msg(0,"请传入用户");
        }
        if(null==userMapper.selectById(userId)){
            return new Msg(0,"没有此用户");
        }
        return orderService.addOrder(userId,strToJson);
    }
}
